﻿
@{
    ViewBag.Title = "用户列表";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<section class="content-header">
    <h1>
        用户管理
        <small></small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>主页</a></li>
        <li class="active">用户列表</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-header">
                    <form id="search-form" class="form-inline">
                        <div class="form-group">
                            <label>电话</label>
                            <input type="text" class="form-control" style="width:100px;" maxlength="11" name="Mobile" autocomplete="off" />
                            <input type="hidden" value="@ViewBag.GroupID" id="CarGroupId" name="CarGroupId" />
                        </div>
                        <div class="form-group">
                            <label>姓名</label>
                            <input type="text" class="form-control" style="width:100px;" maxlength="50" name="UserName" autocomplete="off" />
                        </div>
                        <div class="form-group">
                            <label>卡级别</label>
                            <select id="CardLevel" name="CardLevel" class="form-control">
                                <option value="0">全部</option>
                            </select>
                        </div>
                        <div data-toggle="distpicker" class="form-group">
                            <label>所在地</label>
                            <select name="HProince" id="HProince" class="form-control"></select>
                            <select name="HCity" id="HCity" class="form-control"></select>
                        </div>
                        <div class="form-group">
                            <label>微信号</label>
                            <input type="text" class="form-control" style="width:100px;" name="WeChartNum" autocomplete="off" />
                        </div>
                        <div class="form-group">
                            <label>创建时间</label>
                            <input type="text" class="form-control" style="width:100px;" name="BCreateDate" id="BCreateDate" autocomplete="off" />
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control" style="width:100px;" name="ECreateDate" id="ECreateDate" autocomplete="off" />
                        </div>
                        <div class="form-group">
                            <button type="button" class="btn btn-success btn-sm" id="btnSearch">查找</button>
                        </div>

                        <h3 class="box-title"></h3>
                    </form>
                </div>
                <!-- /.box-header -->
                <div class="box-body table-responsive no-padding">
                    <table class="table table-bordered table-hover body-table-head">
                        <thead>
                            <tr>
                                <th>
                                    用户名称
                                </th>
                                <th>
                                    电话
                                </th>
                                <th>
                                    微信号
                                </th>
                                <th>
                                    卡号
                                </th>
                                <th>
                                    支付状态
                                </th>
                                <th>
                                    审核状态
                                </th>
                                <th>
                                    创建时间
                                </th>
                                <th class="t_c">
                                    操作
                                </th>
                            </tr>
                        </thead>
                        <tbody id="tbodylist"></tbody>
                    </table>
                    <div class="no-data" id="nodata" style="display:none;">
                        <div class="img-box"></div>
                        <div class="text">暂无数据</div>
                    </div>
                </div>
                <div class="box-footer clearfix ">
                    <ul id="pagination" class="pagination pagination-sm no-margin pull-right"></ul>
                </div>
                <!-- /.box-body -->
                <!-- /.box -->
            </div>
        </div>
    </div>

    <div class="modal fade" id="modal-wechart" style="display: none;">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                    <h4 class="modal-title">微信信息</h4>
                </div>
                <div id="modal-body" class="modal-body">

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" data-dismiss="modal">确定</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <!-- 审批模态框（Modal） -->
    <div class="modal fade" id="vehicleModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">行驶证信息</h4>
                </div>
                <div class="modal-body" id="modal_VehicleInfo">正在加载中。。。</div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" id="model_btn_yes">通过</button>
                    <button type="button" class="btn btn-primary" id="model_btn_no">驳回</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
</section>
@section scriptsBottom{
    <script src="@Url.Content("~/lib/art-template/template-web.js")"></script>
    <script id="dataItemTpl" type="text/html">
        {{each rows}}
        <tr>
            <td class="title">
                {{$value.UserName}}
            </td>
            <td class="title">
                {{$value.Mobile}}
            </td>
            <td class="title">
                {{$value.WeChartNum}}
            </td>
            <td>
                {{$value.CardCode}}
            </td>
            <td>
                {{$value.PayStateName}}
            </td>
            {{if $value.VehicleStatus==1}}
            <td>
                未审批
            </td>
            {{else if  $value.VehicleStatus==2}}
            <td>
                通过
            </td>
            {{else if $value.VehicleStatus==3}}
            <td>
                驳回
            </td>
            {{else}}
            <td></td>
            {{/if}}
            <td>
                {{$value.CreateDate}}
            </td>
            <td class="t_c">
                <button type="button" class="btn btn-info btn-xs" onclick="detail('{{$value.UserID}}')">详情</button>
                <button type="button" class="btn btn-info btn-xs" onclick="wechart('{{$value.OpenID}}','{{$value.UnionID}}')">微信</button>
                @*<button type="button" class="btn btn-info btn-xs" onclick="customer('{{$value.UserID}}')">客户</button>*@
                @*<button type="button" class="btn btn-info btn-xs" onclick="driving('{{$value.UserID}}')">驾驶证</button>*@
                @*<button type="button" class="btn btn-info btn-xs" onclick="insure('{{$value.UserID}}')">保险</button>*@
                {{if $value.VehicleStatus==1}}
                <button type="button" class="btn btn-info btn-xs" onclick="approval('{{$value.UserID}}')">审核</button>
                {{/if}}
                <button type="button" class="btn btn-info btn-xs" onclick="vehicle('{{$value.UserID}}')">行驶证</button>
            </td>
        </tr>
        {{/each}}
    </script>
    <script type="text/javascript">
        var modal_UserID = 0;

        function driving(userid) {
             var url = '@Url.Action("Detail", "DrivingLicense")' + "?userId=" + userid;
            location.href = url;
        }
        function insure(userid) {
             var url = '@Url.Action("Detail", "Insure")' + "?userId=" + userid;
            location.href = url;
        }
        function vehicle(userid) {
             var url = '@Url.Action("Detail", "VehicleLicense")' + "?userId=" + userid;
            location.href = url;
        }
        function approval(userid) {
            var url = '@Url.Action("ModalVehicleDetail", "VehicleLicense")' + "?userId=" + userid;
             modal_UserID = userid;
             $("#modal_VehicleInfo").load(url);
             $("#vehicleModal").modal('show');
        }
        $(document).ready(function () {
            $("#BCreateDate").datepicker({
                language: "zh-CN",
                autoclose: true,//选中之后自动隐藏日期选择框
                format: "yyyy-mm-dd"//日期格式，
            });
            $("#ECreateDate").datepicker({
                language: "zh-CN",
                autoclose: true,//选中之后自动隐藏日期选择框
                format: "yyyy-mm-dd"//日期格式，
            });

            $("#btnSearch").click(function () {
                pageIndex = 1;
                list();
            });
            $("#model_btn_yes").click(function () {
                updateVehiclStatus(2);
            });
            $("#model_btn_no").click(function () {
                updateVehiclStatus(3);
            });
            list();
            bindCard();
        });
        function updateVehiclStatus(status) {
            var url = '@Url.Action("SetVehileStatus", "User")';
            var data = {
                "UserID": modal_UserID,
                "VehicleStatus": status
            };
            BMCW.ajax({
                url: url,
                type: "POST",
                data: data,
                success: function (res) {
                    if (res.status == 0) {
                        BMCW.alert("审批提交成功");
                        pageIndex = 1;
                        list();
                    } else {
                        BMCW.alert(res.message);
                    }
                    $("#vehicleModal").modal('hide');
                },
                error: function (err) {
                    $("#modal_VehicleInfo").html("正在加载中。。。");
                    modal_UserID = 0;
                    $("#vehicleModal").modal('hide');
                }
            });
        }
        //页码
        var pageIndex = 1;
        //查询
        function list() {
            var fdata = $("#search-form").serializeJson()
            var url = '@Url.Action("List", "User")' + "?page=" + pageIndex;
            //查询列表
            BMCW.ajax({
                url: url,
                type: 'POST',
                dataType: "json",
                data: fdata,
                success: function (dt) {
                    if (dt.total < 1) {
                        $("#nodata").show();
                        document.getElementById('tbodylist').innerHTML = "";
                        return;
                    }
                    $("#nodata").hide();
                    //模板渲染
                    var data = dt.rows;
                    var html = template('dataItemTpl', dt);
                    document.getElementById('tbodylist').innerHTML = html;
                    //分页显示
                    $('#pagination').twbsPagination("destroy");
                    $('#pagination').twbsPagination({
                        totalItems: dt.total,
                        visiblePages: 10,
                        pageSize: 10,
                        startPage: parseInt(pageIndex),
                        onPageClick: function (event, page) {
                            pageIndex = page;
                            list();
                        }
                    });
                }
            });
        }

        //用户详情
        function detail(userid) {
            var url = '@Url.Action("Detail", "User")' + "?userId=" + userid;
            location.href = url;
        }
        //客户
        function customer(userid) {
            var url = '@Url.Action("Index", "Customer")' + "?userId=" + userid;
            location.href = url;
        }
        //微信信息
        function wechart(openid, unionid) {
            var oid = openid || "";
            var uid = unionid || "";
            var url = '@Url.Action("Index", "WeChartUser")' + "?openid=" + oid + "&unionid=" + uid;
            //$("#modal-body").load(url, function () {
            //    $("#modal-wechart").modal("show");
            //});
            window.location.href = url;
        }

        function bindCard() {
            var url = '@Url.Action("GetActiveCardList", "Customer")'
            BMCW.ajax({
                url: url,
                type: "GET",
                success: function (o) {
                    if (o.length > 0) {
                        for (var i = 0; i < o.length; i++) {
                            $("#CardLevel").append('<option value=' + o[i].CardId + '>' + o[i].Name + '</option>');
                        }

                    } else {
                        BMCW.alert(o.message);
                    }
                }
            });
        }
    </script>
}
